package com.yuyu.sequence.service.entity;

/**
 * @author yuyu
 * @date 2018/12/27
 */
public class LinkedStack<T> {

    private class Node<U> {

        U item;
        Node<U> next;

        public Node() {
        }

        public Node(U item, Node<U> next) {
            this.item = item;
            this.next = next;
        }

        boolean isEnd() {
            return item == null && next == null;
        }
    }

    private Node<T> top = new Node<>();

    public void push(T item) {
        top = new Node<T>(item, top);
    }

    public T pop() {
        T result = top.item;
        if (!top.isEnd()) {
            top = top.next;
        }
        return result;
    }

}
